import { RootState, useSelector } from "@/store";
import { theme } from "antd";
import { MappingAlgorithm } from "antd/es/config-provider/context";

/**
 * @description 全局主题设置
 * */
const useTheme = () => {
	const { isDark } = useSelector((state: RootState) => state.theme.themeConfig);

	// 切换主题暗黑模式
	const initTheme = () => {
		const body = document.documentElement as HTMLElement;
		body.setAttribute("class", isDark ? "dark" : "");
	};

	// 暗色模式
	const darkAlgorithm: MappingAlgorithm = (seedToken, mapToken) => {
		const baseToken = theme.darkAlgorithm(seedToken, mapToken);
		console.log(baseToken);
		return {
			...baseToken,
			colorBgBase: "#1a1a1a", // Layout 背景色
			colorBgElevated: "#1a1a1a"
		};
	};

	initTheme();

	return {
		initTheme,
		theme: {
			algorithm: isDark ? darkAlgorithm : theme.defaultAlgorithm
		}
	};
};
export default useTheme;
